<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Docker Compose 命令说明 | 我的笔记</title>
    <meta name="generator" content="VuePress 1.8.2">
    <link rel="icon" href="/notebook/favicon.ico">
    <script data-ad-client="ca-pub-4147143076931995" async="true" src="/notebook//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <meta name="description" content="方便阅读和寻找">
    
    <link rel="preload" href="/notebook/assets/css/0.styles.cee65b40.css" as="style"><link rel="preload" href="/notebook/assets/js/app.400f01da.js" as="script"><link rel="preload" href="/notebook/assets/js/2.ffba27f2.js" as="script"><link rel="preload" href="/notebook/assets/js/77.fa7ddd5d.js" as="script"><link rel="prefetch" href="/notebook/assets/js/10.9da57264.js"><link rel="prefetch" href="/notebook/assets/js/100.8aa79850.js"><link rel="prefetch" href="/notebook/assets/js/101.f8819976.js"><link rel="prefetch" href="/notebook/assets/js/102.7168e4aa.js"><link rel="prefetch" href="/notebook/assets/js/103.e1f049f7.js"><link rel="prefetch" href="/notebook/assets/js/104.0ada8567.js"><link rel="prefetch" href="/notebook/assets/js/105.77e95b95.js"><link rel="prefetch" href="/notebook/assets/js/106.9071202a.js"><link rel="prefetch" href="/notebook/assets/js/107.a0a63241.js"><link rel="prefetch" href="/notebook/assets/js/108.93ccf0bf.js"><link rel="prefetch" href="/notebook/assets/js/109.57caff98.js"><link rel="prefetch" href="/notebook/assets/js/11.d9d769c3.js"><link rel="prefetch" href="/notebook/assets/js/110.6aa16c3f.js"><link rel="prefetch" href="/notebook/assets/js/111.293e18e5.js"><link rel="prefetch" href="/notebook/assets/js/112.7f593e53.js"><link rel="prefetch" href="/notebook/assets/js/113.e03d7fe0.js"><link rel="prefetch" href="/notebook/assets/js/114.4fd73421.js"><link rel="prefetch" href="/notebook/assets/js/115.8dc5910d.js"><link rel="prefetch" href="/notebook/assets/js/116.fc5215b7.js"><link rel="prefetch" href="/notebook/assets/js/117.851bae37.js"><link rel="prefetch" href="/notebook/assets/js/118.03cb2186.js"><link rel="prefetch" href="/notebook/assets/js/119.17f93b7e.js"><link rel="prefetch" href="/notebook/assets/js/12.125d7a59.js"><link rel="prefetch" href="/notebook/assets/js/120.4ea767fb.js"><link rel="prefetch" href="/notebook/assets/js/121.483ad579.js"><link rel="prefetch" href="/notebook/assets/js/122.17d2596f.js"><link rel="prefetch" href="/notebook/assets/js/123.56e20e4e.js"><link rel="prefetch" href="/notebook/assets/js/124.2ec822f9.js"><link rel="prefetch" href="/notebook/assets/js/125.bccb84ed.js"><link rel="prefetch" href="/notebook/assets/js/126.e38a7466.js"><link rel="prefetch" href="/notebook/assets/js/127.43962ebd.js"><link rel="prefetch" href="/notebook/assets/js/128.23f8246b.js"><link rel="prefetch" href="/notebook/assets/js/129.e718e26c.js"><link rel="prefetch" href="/notebook/assets/js/13.f56b83ad.js"><link rel="prefetch" href="/notebook/assets/js/130.a51fe94d.js"><link rel="prefetch" href="/notebook/assets/js/131.64fb54a3.js"><link rel="prefetch" href="/notebook/assets/js/132.badc2a1a.js"><link rel="prefetch" href="/notebook/assets/js/133.72f12c19.js"><link rel="prefetch" href="/notebook/assets/js/134.0b1b2dc0.js"><link rel="prefetch" href="/notebook/assets/js/135.be2d740c.js"><link rel="prefetch" href="/notebook/assets/js/136.c3dc9ba1.js"><link rel="prefetch" href="/notebook/assets/js/137.784510e4.js"><link rel="prefetch" href="/notebook/assets/js/138.ff844e48.js"><link rel="prefetch" href="/notebook/assets/js/139.1ac43f97.js"><link rel="prefetch" href="/notebook/assets/js/14.3ed225c4.js"><link rel="prefetch" href="/notebook/assets/js/140.4c427bf3.js"><link rel="prefetch" href="/notebook/assets/js/141.459f2cb4.js"><link rel="prefetch" href="/notebook/assets/js/142.e69e2b00.js"><link rel="prefetch" href="/notebook/assets/js/143.b9cd433a.js"><link rel="prefetch" href="/notebook/assets/js/144.c12cb09a.js"><link rel="prefetch" href="/notebook/assets/js/145.43e25cc4.js"><link rel="prefetch" href="/notebook/assets/js/146.0963c075.js"><link rel="prefetch" href="/notebook/assets/js/147.37f2e690.js"><link rel="prefetch" href="/notebook/assets/js/148.631fbe69.js"><link rel="prefetch" href="/notebook/assets/js/149.a22c5490.js"><link rel="prefetch" href="/notebook/assets/js/15.10a06d24.js"><link rel="prefetch" href="/notebook/assets/js/150.e6265d54.js"><link rel="prefetch" href="/notebook/assets/js/151.aefdb9fd.js"><link rel="prefetch" href="/notebook/assets/js/152.a8c722bd.js"><link rel="prefetch" href="/notebook/assets/js/153.ec2b1513.js"><link rel="prefetch" href="/notebook/assets/js/154.4fdc765f.js"><link rel="prefetch" href="/notebook/assets/js/155.de537bd1.js"><link rel="prefetch" href="/notebook/assets/js/156.7f87247c.js"><link rel="prefetch" href="/notebook/assets/js/157.f51afdd1.js"><link rel="prefetch" href="/notebook/assets/js/158.247f3f23.js"><link rel="prefetch" href="/notebook/assets/js/159.2342ec68.js"><link rel="prefetch" href="/notebook/assets/js/16.bc052b7f.js"><link rel="prefetch" href="/notebook/assets/js/160.98e33fe9.js"><link rel="prefetch" href="/notebook/assets/js/161.b8389795.js"><link rel="prefetch" href="/notebook/assets/js/162.5809ad21.js"><link rel="prefetch" href="/notebook/assets/js/163.6d40855f.js"><link rel="prefetch" href="/notebook/assets/js/164.cd5e8c28.js"><link rel="prefetch" href="/notebook/assets/js/165.c409d97c.js"><link rel="prefetch" href="/notebook/assets/js/166.75cd78fe.js"><link rel="prefetch" href="/notebook/assets/js/167.37552374.js"><link rel="prefetch" href="/notebook/assets/js/168.d4ab1d56.js"><link rel="prefetch" href="/notebook/assets/js/169.39f3c518.js"><link rel="prefetch" href="/notebook/assets/js/17.2a8873d5.js"><link rel="prefetch" href="/notebook/assets/js/170.7993242d.js"><link rel="prefetch" href="/notebook/assets/js/171.09f40b60.js"><link rel="prefetch" href="/notebook/assets/js/172.79168981.js"><link rel="prefetch" href="/notebook/assets/js/173.a75cd141.js"><link rel="prefetch" href="/notebook/assets/js/174.bd510afd.js"><link rel="prefetch" href="/notebook/assets/js/175.c3f8ba94.js"><link rel="prefetch" href="/notebook/assets/js/176.dd9cbd79.js"><link rel="prefetch" href="/notebook/assets/js/177.f53090f5.js"><link rel="prefetch" href="/notebook/assets/js/178.bcda53b0.js"><link rel="prefetch" href="/notebook/assets/js/179.2d510aa5.js"><link rel="prefetch" href="/notebook/assets/js/18.2d0a0d6d.js"><link rel="prefetch" href="/notebook/assets/js/180.6928e4f9.js"><link rel="prefetch" href="/notebook/assets/js/181.6cc94652.js"><link rel="prefetch" href="/notebook/assets/js/182.c7d6fde2.js"><link rel="prefetch" href="/notebook/assets/js/183.1a7eaa90.js"><link rel="prefetch" href="/notebook/assets/js/184.5d52b650.js"><link rel="prefetch" href="/notebook/assets/js/185.2f8eddcd.js"><link rel="prefetch" href="/notebook/assets/js/186.2615bcf2.js"><link rel="prefetch" href="/notebook/assets/js/187.ffb3009d.js"><link rel="prefetch" href="/notebook/assets/js/188.deef127e.js"><link rel="prefetch" href="/notebook/assets/js/189.51b1958b.js"><link rel="prefetch" href="/notebook/assets/js/19.482e846f.js"><link rel="prefetch" href="/notebook/assets/js/190.a5e85724.js"><link rel="prefetch" href="/notebook/assets/js/191.fd2dfc70.js"><link rel="prefetch" href="/notebook/assets/js/192.5cb3b141.js"><link rel="prefetch" href="/notebook/assets/js/193.3a6173b0.js"><link rel="prefetch" href="/notebook/assets/js/194.2b937e4b.js"><link rel="prefetch" href="/notebook/assets/js/195.71b1b3e2.js"><link rel="prefetch" href="/notebook/assets/js/196.d8d64ba1.js"><link rel="prefetch" href="/notebook/assets/js/197.fbea3131.js"><link rel="prefetch" href="/notebook/assets/js/198.25e90057.js"><link rel="prefetch" href="/notebook/assets/js/199.5bef52d0.js"><link rel="prefetch" href="/notebook/assets/js/20.3869e9c1.js"><link rel="prefetch" href="/notebook/assets/js/200.839b8484.js"><link rel="prefetch" href="/notebook/assets/js/201.dcc87a43.js"><link rel="prefetch" href="/notebook/assets/js/202.83abe52e.js"><link rel="prefetch" href="/notebook/assets/js/203.c8c886fe.js"><link rel="prefetch" href="/notebook/assets/js/204.7d91a0aa.js"><link rel="prefetch" href="/notebook/assets/js/205.dd934d84.js"><link rel="prefetch" href="/notebook/assets/js/206.ae9d7602.js"><link rel="prefetch" href="/notebook/assets/js/207.f5ac5260.js"><link rel="prefetch" href="/notebook/assets/js/208.203ba066.js"><link rel="prefetch" href="/notebook/assets/js/209.202991be.js"><link rel="prefetch" href="/notebook/assets/js/21.95b2d828.js"><link rel="prefetch" href="/notebook/assets/js/210.3e7c6db0.js"><link rel="prefetch" href="/notebook/assets/js/211.d231f4d5.js"><link rel="prefetch" href="/notebook/assets/js/212.74210f2c.js"><link rel="prefetch" href="/notebook/assets/js/213.ca497e10.js"><link rel="prefetch" href="/notebook/assets/js/214.256f2f8d.js"><link rel="prefetch" href="/notebook/assets/js/215.e5a91195.js"><link rel="prefetch" href="/notebook/assets/js/22.bfedf3cf.js"><link rel="prefetch" href="/notebook/assets/js/23.07416482.js"><link rel="prefetch" href="/notebook/assets/js/24.54aaf5dd.js"><link rel="prefetch" href="/notebook/assets/js/25.5fddfc47.js"><link rel="prefetch" href="/notebook/assets/js/26.3beace9a.js"><link rel="prefetch" href="/notebook/assets/js/27.8166fc8b.js"><link rel="prefetch" href="/notebook/assets/js/28.45eec4fe.js"><link rel="prefetch" href="/notebook/assets/js/29.7d2c15a3.js"><link rel="prefetch" href="/notebook/assets/js/3.58b1a014.js"><link rel="prefetch" href="/notebook/assets/js/30.a7841312.js"><link rel="prefetch" href="/notebook/assets/js/31.dc9675e8.js"><link rel="prefetch" href="/notebook/assets/js/32.93c6c35d.js"><link rel="prefetch" href="/notebook/assets/js/33.9a64b2f6.js"><link rel="prefetch" href="/notebook/assets/js/34.0c220f3c.js"><link rel="prefetch" href="/notebook/assets/js/35.9f407421.js"><link rel="prefetch" href="/notebook/assets/js/36.ee8ac781.js"><link rel="prefetch" href="/notebook/assets/js/37.569079d1.js"><link rel="prefetch" href="/notebook/assets/js/38.56b32d83.js"><link rel="prefetch" href="/notebook/assets/js/39.6ea9c955.js"><link rel="prefetch" href="/notebook/assets/js/4.5042ba18.js"><link rel="prefetch" href="/notebook/assets/js/40.5bdebc85.js"><link rel="prefetch" href="/notebook/assets/js/41.8607bd5a.js"><link rel="prefetch" href="/notebook/assets/js/42.2063b1d0.js"><link rel="prefetch" href="/notebook/assets/js/43.ff59782c.js"><link rel="prefetch" href="/notebook/assets/js/44.c40eaded.js"><link rel="prefetch" href="/notebook/assets/js/45.bc61bb49.js"><link rel="prefetch" href="/notebook/assets/js/46.e9ea5687.js"><link rel="prefetch" href="/notebook/assets/js/47.a9626a0e.js"><link rel="prefetch" href="/notebook/assets/js/48.9bf986fe.js"><link rel="prefetch" href="/notebook/assets/js/49.dd90158a.js"><link rel="prefetch" href="/notebook/assets/js/5.b9679d2a.js"><link rel="prefetch" href="/notebook/assets/js/50.a9546c5a.js"><link rel="prefetch" href="/notebook/assets/js/51.dcc646ec.js"><link rel="prefetch" href="/notebook/assets/js/52.111a35ff.js"><link rel="prefetch" href="/notebook/assets/js/53.19719081.js"><link rel="prefetch" href="/notebook/assets/js/54.543f990e.js"><link rel="prefetch" href="/notebook/assets/js/55.02863756.js"><link rel="prefetch" href="/notebook/assets/js/56.262a1288.js"><link rel="prefetch" href="/notebook/assets/js/57.a80801ee.js"><link rel="prefetch" href="/notebook/assets/js/58.38d623bc.js"><link rel="prefetch" href="/notebook/assets/js/59.07a6b6b6.js"><link rel="prefetch" href="/notebook/assets/js/6.77dfe150.js"><link rel="prefetch" href="/notebook/assets/js/60.df11d23d.js"><link rel="prefetch" href="/notebook/assets/js/61.764a5b2e.js"><link rel="prefetch" href="/notebook/assets/js/62.28916805.js"><link rel="prefetch" href="/notebook/assets/js/63.f54fb2ba.js"><link rel="prefetch" href="/notebook/assets/js/64.73bb9e27.js"><link rel="prefetch" href="/notebook/assets/js/65.8e45d2c8.js"><link rel="prefetch" href="/notebook/assets/js/66.6cabc639.js"><link rel="prefetch" href="/notebook/assets/js/67.61f4e99c.js"><link rel="prefetch" href="/notebook/assets/js/68.fec9c74e.js"><link rel="prefetch" href="/notebook/assets/js/69.b530b731.js"><link rel="prefetch" href="/notebook/assets/js/7.bac04506.js"><link rel="prefetch" href="/notebook/assets/js/70.e2902def.js"><link rel="prefetch" href="/notebook/assets/js/71.09df6e0a.js"><link rel="prefetch" href="/notebook/assets/js/72.5c611ac8.js"><link rel="prefetch" href="/notebook/assets/js/73.66c43b39.js"><link rel="prefetch" href="/notebook/assets/js/74.243e6a2f.js"><link rel="prefetch" href="/notebook/assets/js/75.de524cab.js"><link rel="prefetch" href="/notebook/assets/js/76.750c2fc0.js"><link rel="prefetch" href="/notebook/assets/js/78.192816fd.js"><link rel="prefetch" href="/notebook/assets/js/79.a3f3fcd9.js"><link rel="prefetch" href="/notebook/assets/js/8.48754361.js"><link rel="prefetch" href="/notebook/assets/js/80.c3fd6acb.js"><link rel="prefetch" href="/notebook/assets/js/81.7ba4627a.js"><link rel="prefetch" href="/notebook/assets/js/82.e355d704.js"><link rel="prefetch" href="/notebook/assets/js/83.2579aea2.js"><link rel="prefetch" href="/notebook/assets/js/84.1f72cccf.js"><link rel="prefetch" href="/notebook/assets/js/85.7874726d.js"><link rel="prefetch" href="/notebook/assets/js/86.a863f0c3.js"><link rel="prefetch" href="/notebook/assets/js/87.c8c7690e.js"><link rel="prefetch" href="/notebook/assets/js/88.5d7963f9.js"><link rel="prefetch" href="/notebook/assets/js/89.9391f30b.js"><link rel="prefetch" href="/notebook/assets/js/9.c2fb6f2c.js"><link rel="prefetch" href="/notebook/assets/js/90.76bedd2e.js"><link rel="prefetch" href="/notebook/assets/js/91.e345e87a.js"><link rel="prefetch" href="/notebook/assets/js/92.175f428e.js"><link rel="prefetch" href="/notebook/assets/js/93.f45b4417.js"><link rel="prefetch" href="/notebook/assets/js/94.e3f459de.js"><link rel="prefetch" href="/notebook/assets/js/95.1632f845.js"><link rel="prefetch" href="/notebook/assets/js/96.4d0a41d5.js"><link rel="prefetch" href="/notebook/assets/js/97.39bd1831.js"><link rel="prefetch" href="/notebook/assets/js/98.54282751.js"><link rel="prefetch" href="/notebook/assets/js/99.b60593a3.js">
    <link rel="stylesheet" href="/notebook/assets/css/0.styles.cee65b40.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/notebook/" class="home-link router-link-active"><!----> <span class="site-name">我的笔记</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/notebook/guide/" class="nav-link">
  指南
</a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/notebook/guide/" class="nav-link">
  指南
</a></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>Docker Compose</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/notebook/docker-compose/" aria-current="page" class="sidebar-link">什么是 Docker Compose</a></li><li><a href="/notebook/docker-compose/Docker Compose 安装与卸载.html" class="sidebar-link">Docker Compose 安装与卸载</a></li><li><a href="/notebook/docker-compose/Docker Compose 使用.html" class="sidebar-link">Docker Compose 使用</a></li><li><a href="/notebook/docker-compose/Docker Compose 命令说明.html" class="active sidebar-link">Docker Compose 命令说明</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/notebook/docker-compose/Docker Compose 命令说明.html#命令对象与格式" class="sidebar-link">命令对象与格式</a></li><li class="sidebar-sub-header"><a href="/notebook/docker-compose/Docker Compose 命令说明.html#命令选项" class="sidebar-link">命令选项</a></li><li class="sidebar-sub-header"><a href="/notebook/docker-compose/Docker Compose 命令说明.html#build" class="sidebar-link">build</a></li><li class="sidebar-sub-header"><a href="/notebook/docker-compose/Docker Compose 命令说明.html#config" class="sidebar-link">config</a></li><li class="sidebar-sub-header"><a href="/notebook/docker-compose/Docker Compose 命令说明.html#down" class="sidebar-link">down</a></li><li class="sidebar-sub-header"><a href="/notebook/docker-compose/Docker Compose 命令说明.html#exec" class="sidebar-link">exec</a></li><li class="sidebar-sub-header"><a href="/notebook/docker-compose/Docker Compose 命令说明.html#help" class="sidebar-link">help</a></li><li class="sidebar-sub-header"><a href="/notebook/docker-compose/Docker Compose 命令说明.html#images" class="sidebar-link">images</a></li><li class="sidebar-sub-header"><a href="/notebook/docker-compose/Docker Compose 命令说明.html#kill" class="sidebar-link">kill</a></li><li class="sidebar-sub-header"><a href="/notebook/docker-compose/Docker Compose 命令说明.html#logs" class="sidebar-link">logs</a></li><li class="sidebar-sub-header"><a href="/notebook/docker-compose/Docker Compose 命令说明.html#pause" class="sidebar-link">pause</a></li><li class="sidebar-sub-header"><a href="/notebook/docker-compose/Docker Compose 命令说明.html#port" class="sidebar-link">port</a></li><li class="sidebar-sub-header"><a href="/notebook/docker-compose/Docker Compose 命令说明.html#ps" class="sidebar-link">ps</a></li><li class="sidebar-sub-header"><a href="/notebook/docker-compose/Docker Compose 命令说明.html#pull" class="sidebar-link">pull</a></li><li class="sidebar-sub-header"><a href="/notebook/docker-compose/Docker Compose 命令说明.html#push" class="sidebar-link">push</a></li><li class="sidebar-sub-header"><a href="/notebook/docker-compose/Docker Compose 命令说明.html#restart" class="sidebar-link">restart</a></li><li class="sidebar-sub-header"><a href="/notebook/docker-compose/Docker Compose 命令说明.html#rm" class="sidebar-link">rm</a></li><li class="sidebar-sub-header"><a href="/notebook/docker-compose/Docker Compose 命令说明.html#run" class="sidebar-link">run</a></li><li class="sidebar-sub-header"><a href="/notebook/docker-compose/Docker Compose 命令说明.html#scale" class="sidebar-link">scale</a></li><li class="sidebar-sub-header"><a href="/notebook/docker-compose/Docker Compose 命令说明.html#start" class="sidebar-link">start</a></li><li class="sidebar-sub-header"><a href="/notebook/docker-compose/Docker Compose 命令说明.html#stop" class="sidebar-link">stop</a></li><li class="sidebar-sub-header"><a href="/notebook/docker-compose/Docker Compose 命令说明.html#top" class="sidebar-link">top</a></li><li class="sidebar-sub-header"><a href="/notebook/docker-compose/Docker Compose 命令说明.html#unpause" class="sidebar-link">unpause</a></li><li class="sidebar-sub-header"><a href="/notebook/docker-compose/Docker Compose 命令说明.html#up" class="sidebar-link">up</a></li><li class="sidebar-sub-header"><a href="/notebook/docker-compose/Docker Compose 命令说明.html#version" class="sidebar-link">version</a></li></ul></li><li><a href="/notebook/docker-compose/Docker Compose 模板文件.html" class="sidebar-link">Docker Compose 模板文件</a></li><li><a href="/notebook/docker-compose/Docker Compose 实战 Tomcat.html" class="sidebar-link">Docker Compose 实战 Tomcat</a></li><li><a href="/notebook/docker-compose/Docker Compose 实战 MySQL.html" class="sidebar-link">Docker Compose 实战 MySQL</a></li><li><a href="/notebook/docker-compose/Docker Compose 部署项目到容器.html" class="sidebar-link">Docker Compose 部署项目到容器</a></li><li><a href="/notebook/docker-compose/Docker Compose 常用命令.html" class="sidebar-link">Docker Compose 常用命令</a></li><li><a href="/notebook/docker-compose/YAML 配置文件语言.html" class="sidebar-link">YAML 配置文件语言</a></li><li><a href="/notebook/docker-compose/附：为什么说 JSON 不适合做配置文件？.html" class="sidebar-link">附：为什么说 JSON 不适合做配置文件？</a></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="docker-compose-命令说明"><a href="#docker-compose-命令说明" class="header-anchor">#</a> Docker Compose 命令说明</h1> <h2 id="命令对象与格式"><a href="#命令对象与格式" class="header-anchor">#</a> 命令对象与格式</h2> <p>对于 Compose 来说，大部分命令的对象既可以是项目本身，也可以指定为项目中的服务或者容器。如果没有特别的说明，命令对象将是项目，这意味着项目中所有的服务都会受到命令影响。</p> <p>执行 <code>docker-compose [COMMAND] --help</code> 或者 <code>docker-compose help [COMMAND]</code> 可以查看具体某个命令的使用格式。</p> <p><code>docker-compose</code> 命令的基本的使用格式是</p> <div class="language-bash extra-class"><pre class="language-bash"><code>docker-compose <span class="token punctuation">[</span>-f<span class="token operator">=</span><span class="token operator">&lt;</span>arg<span class="token operator">&gt;</span><span class="token punctuation">..</span>.<span class="token punctuation">]</span> <span class="token punctuation">[</span>options<span class="token punctuation">]</span> <span class="token punctuation">[</span>COMMAND<span class="token punctuation">]</span> <span class="token punctuation">[</span>ARGS<span class="token punctuation">..</span>.<span class="token punctuation">]</span>
</code></pre></div><h2 id="命令选项"><a href="#命令选项" class="header-anchor">#</a> 命令选项</h2> <ul><li><code>-f, --file FILE</code> 指定使用的 Compose 模板文件，默认为 <code>docker-compose.yml</code>，可以多次指定。</li> <li><code>-p, --project-name NAME</code> 指定项目名称，默认将使用所在目录名称作为项目名。</li> <li><code>--x-networking</code> 使用 Docker 的可拔插网络后端特性</li> <li><code>--x-network-driver DRIVER</code> 指定网络后端的驱动，默认为 <code>bridge</code></li> <li><code>--verbose</code> 输出更多调试信息。</li> <li><code>-v, --version</code> 打印版本并退出。</li></ul> <h2 id="build"><a href="#build" class="header-anchor">#</a> <code>build</code></h2> <p>格式为 <code>docker-compose build [options] [SERVICE...]</code>。</p> <p>构建（重新构建）项目中的服务容器。</p> <p>服务容器一旦构建后，将会带上一个标记名，例如对于 web 项目中的一个 db 容器，可能是 web_db。</p> <p>可以随时在项目目录下运行 <code>docker-compose build</code> 来重新构建服务。</p> <p>选项包括：</p> <ul><li><code>--force-rm</code> 删除构建过程中的临时容器。</li> <li><code>--no-cache</code> 构建镜像过程中不使用 cache（这将加长构建过程）。</li> <li><code>--pull</code> 始终尝试通过 pull 来获取更新版本的镜像。</li></ul> <h2 id="config"><a href="#config" class="header-anchor">#</a> <code>config</code></h2> <p>验证 Compose 文件格式是否正确，若正确则显示配置，若格式错误显示错误原因。</p> <h2 id="down"><a href="#down" class="header-anchor">#</a> <code>down</code></h2> <p>此命令将会停止 <code>up</code> 命令所启动的容器，并移除网络</p> <h2 id="exec"><a href="#exec" class="header-anchor">#</a> <code>exec</code></h2> <p>进入指定的容器。</p> <h2 id="help"><a href="#help" class="header-anchor">#</a> <code>help</code></h2> <p>获得一个命令的帮助。</p> <h2 id="images"><a href="#images" class="header-anchor">#</a> <code>images</code></h2> <p>列出 Compose 文件中包含的镜像。</p> <h2 id="kill"><a href="#kill" class="header-anchor">#</a> <code>kill</code></h2> <p>格式为 <code>docker-compose kill [options] [SERVICE...]</code>。</p> <p>通过发送 <code>SIGKILL</code> 信号来强制停止服务容器。</p> <p>支持通过 <code>-s</code> 参数来指定发送的信号，例如通过如下指令发送 <code>SIGINT</code> 信号。</p> <div class="language-bash extra-class"><pre class="language-bash"><code>$ docker-compose <span class="token function">kill</span> -s SIGINT
</code></pre></div><h2 id="logs"><a href="#logs" class="header-anchor">#</a> <code>logs</code></h2> <p>格式为 <code>docker-compose logs [options] [SERVICE...]</code>。</p> <p>查看服务容器的输出。默认情况下，docker-compose 将对不同的服务输出使用不同的颜色来区分。可以通过 <code>--no-color</code> 来关闭颜色。</p> <p>该命令在调试问题的时候十分有用。</p> <h2 id="pause"><a href="#pause" class="header-anchor">#</a> <code>pause</code></h2> <p>格式为 <code>docker-compose pause [SERVICE...]</code>。</p> <p>暂停一个服务容器。</p> <h2 id="port"><a href="#port" class="header-anchor">#</a> <code>port</code></h2> <p>格式为 <code>docker-compose port [options] SERVICE PRIVATE_PORT</code>。</p> <p>打印某个容器端口所映射的公共端口。</p> <p>选项：</p> <ul><li><code>--protocol=proto</code> 指定端口协议，tcp（默认值）或者 udp。</li> <li><code>--index=index</code> 如果同一服务存在多个容器，指定命令对象容器的序号（默认为 1）。</li></ul> <h2 id="ps"><a href="#ps" class="header-anchor">#</a> <code>ps</code></h2> <p>格式为 <code>docker-compose ps [options] [SERVICE...]</code>。</p> <p>列出项目中目前的所有容器。</p> <p>选项：</p> <ul><li><code>-q</code> 只打印容器的 ID 信息。</li></ul> <h2 id="pull"><a href="#pull" class="header-anchor">#</a> <code>pull</code></h2> <p>格式为 <code>docker-compose pull [options] [SERVICE...]</code>。</p> <p>拉取服务依赖的镜像。</p> <p>选项：</p> <ul><li><code>--ignore-pull-failures</code> 忽略拉取镜像过程中的错误。</li></ul> <h2 id="push"><a href="#push" class="header-anchor">#</a> <code>push</code></h2> <p>推送服务依赖的镜像到 Docker 镜像仓库。</p> <h2 id="restart"><a href="#restart" class="header-anchor">#</a> <code>restart</code></h2> <p>格式为 <code>docker-compose restart [options] [SERVICE...]</code>。</p> <p>重启项目中的服务。</p> <p>选项：</p> <ul><li><code>-t, --timeout TIMEOUT</code> 指定重启前停止容器的超时（默认为 10 秒）。</li></ul> <h2 id="rm"><a href="#rm" class="header-anchor">#</a> <code>rm</code></h2> <p>格式为 <code>docker-compose rm [options] [SERVICE...]</code>。</p> <p>删除所有（停止状态的）服务容器。推荐先执行 <code>docker-compose stop</code> 命令来停止容器。</p> <p>选项：</p> <ul><li><code>-f, --force</code> 强制直接删除，包括非停止状态的容器。一般尽量不要使用该选项。</li> <li><code>-v</code> 删除容器所挂载的数据卷。</li></ul> <h2 id="run"><a href="#run" class="header-anchor">#</a> <code>run</code></h2> <p>格式为 <code>docker-compose run [options] [-p PORT...] [-e KEY=VAL...] SERVICE [COMMAND] [ARGS...]</code>。</p> <p>在指定服务上执行一个命令。</p> <p>例如：</p> <div class="language-bash extra-class"><pre class="language-bash"><code>$ docker-compose run ubuntu <span class="token function">ping</span> docker.com
</code></pre></div><p>将会启动一个 ubuntu 服务容器，并执行 <code>ping docker.com</code> 命令。</p> <p>默认情况下，如果存在关联，则所有关联的服务将会自动被启动，除非这些服务已经在运行中。</p> <p>该命令类似启动容器后运行指定的命令，相关卷、链接等等都将会按照配置自动创建。</p> <p>两个不同点：</p> <ul><li>给定命令将会覆盖原有的自动运行命令；</li> <li>不会自动创建端口，以避免冲突。</li></ul> <p>如果不希望自动启动关联的容器，可以使用 <code>--no-deps</code> 选项，例如</p> <div class="language-bash extra-class"><pre class="language-bash"><code>$ docker-compose run --no-deps web python manage.py shell
</code></pre></div><p>将不会启动 web 容器所关联的其它容器。</p> <p>选项：</p> <ul><li><code>-d</code> 后台运行容器。</li> <li><code>--name NAME</code> 为容器指定一个名字。</li> <li><code>--entrypoint CMD</code> 覆盖默认的容器启动指令。</li> <li><code>-e KEY=VAL</code> 设置环境变量值，可多次使用选项来设置多个环境变量。</li> <li><code>-u, --user=&quot;&quot;</code> 指定运行容器的用户名或者 uid。</li> <li><code>--no-deps</code> 不自动启动关联的服务容器。</li> <li><code>--rm</code> 运行命令后自动删除容器，<code>d</code> 模式下将忽略。</li> <li><code>-p, --publish=[]</code> 映射容器端口到本地主机。</li> <li><code>--service-ports</code> 配置服务端口并映射到本地主机。</li> <li><code>-T</code> 不分配伪 tty，意味着依赖 tty 的指令将无法运行。</li></ul> <h2 id="scale"><a href="#scale" class="header-anchor">#</a> <code>scale</code></h2> <p>格式为 <code>docker-compose scale [options] [SERVICE=NUM...]</code>。</p> <p>设置指定服务运行的容器个数。</p> <p>通过 <code>service=num</code> 的参数来设置数量。例如：</p> <div class="language-bash extra-class"><pre class="language-bash"><code>$ docker-compose scale <span class="token assign-left variable">web</span><span class="token operator">=</span><span class="token number">3</span> <span class="token assign-left variable">db</span><span class="token operator">=</span><span class="token number">2</span>
</code></pre></div><p>将启动 3 个容器运行 web 服务，2 个容器运行 db 服务。</p> <p>一般的，当指定数目多于该服务当前实际运行容器，将新创建并启动容器；反之，将停止容器。</p> <p>选项：</p> <ul><li><code>-t, --timeout TIMEOUT</code> 停止容器时候的超时（默认为 10 秒）。</li></ul> <h2 id="start"><a href="#start" class="header-anchor">#</a> <code>start</code></h2> <p>格式为 <code>docker-compose start [SERVICE...]</code>。</p> <p>启动已经存在的服务容器。</p> <h2 id="stop"><a href="#stop" class="header-anchor">#</a> <code>stop</code></h2> <p>格式为 <code>docker-compose stop [options] [SERVICE...]</code>。</p> <p>停止已经处于运行状态的容器，但不删除它。通过 <code>docker-compose start</code> 可以再次启动这些容器。</p> <p>选项：</p> <ul><li><code>-t, --timeout TIMEOUT</code> 停止容器时候的超时（默认为 10 秒）。</li></ul> <h2 id="top"><a href="#top" class="header-anchor">#</a> <code>top</code></h2> <p>查看各个服务容器内运行的进程。</p> <h2 id="unpause"><a href="#unpause" class="header-anchor">#</a> <code>unpause</code></h2> <p>格式为 <code>docker-compose unpause [SERVICE...]</code>。</p> <p>恢复处于暂停状态中的服务。</p> <h2 id="up"><a href="#up" class="header-anchor">#</a> <code>up</code></h2> <p>格式为 <code>docker-compose up [options] [SERVICE...]</code>。</p> <p>该命令十分强大，它将尝试自动完成包括构建镜像，（重新）创建服务，启动服务，并关联服务相关容器的一系列操作。</p> <p>链接的服务都将会被自动启动，除非已经处于运行状态。</p> <p>可以说，大部分时候都可以直接通过该命令来启动一个项目。</p> <p>默认情况，<code>docker-compose up</code> 启动的容器都在前台，控制台将会同时打印所有容器的输出信息，可以很方便进行调试。</p> <p>当通过 <code>Ctrl-C</code> 停止命令时，所有容器将会停止。</p> <p>如果使用 <code>docker-compose up -d</code>，将会在后台启动并运行所有的容器。一般推荐生产环境下使用该选项。</p> <p>默认情况，如果服务容器已经存在，<code>docker-compose up</code> 将会尝试停止容器，然后重新创建（保持使用 <code>volumes-from</code> 挂载的卷），以保证新启动的服务匹配 <code>docker-compose.yml</code> 文件的最新内容。如果用户不希望容器被停止并重新创建，可以使用 <code>docker-compose up --no-recreate</code>。这样将只会启动处于停止状态的容器，而忽略已经运行的服务。如果用户只想重新部署某个服务，可以使用 <code>docker-compose up --no-deps -d &lt;SERVICE_NAME&gt;</code> 来重新创建服务并后台停止旧服务，启动新服务，并不会影响到其所依赖的服务。</p> <p>选项：</p> <ul><li><code>-d</code> 在后台运行服务容器。</li> <li><code>--no-color</code> 不使用颜色来区分不同的服务的控制台输出。</li> <li><code>--no-deps</code> 不启动服务所链接的容器。</li> <li><code>--force-recreate</code> 强制重新创建容器，不能与 <code>--no-recreate</code> 同时使用。</li> <li><code>--no-recreate</code> 如果容器已经存在了，则不重新创建，不能与 <code>--force-recreate</code> 同时使用。</li> <li><code>--no-build</code> 不自动构建缺失的服务镜像。</li> <li><code>-t, --timeout TIMEOUT</code> 停止容器时候的超时（默认为 10 秒）。</li></ul> <h2 id="version"><a href="#version" class="header-anchor">#</a> <code>version</code></h2> <p>格式为 <code>docker-compose version</code>。</p> <p>打印版本信息。</p></div> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">2021/4/16 上午12:21:23</span></div></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/notebook/docker-compose/Docker Compose 使用.html" class="prev">
        Docker Compose 使用
      </a></span> <span class="next"><a href="/notebook/docker-compose/Docker Compose 模板文件.html">
        Docker Compose 模板文件
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"><!----></div></div>
    <script src="/notebook/assets/js/app.400f01da.js" defer></script><script src="/notebook/assets/js/2.ffba27f2.js" defer></script><script src="/notebook/assets/js/77.fa7ddd5d.js" defer></script>
  </body>
</html>
